//
//  GetStarredChannelsOfMySelfTableViewCell.m
//  TestApplication
//
//  Created by Hanlingyu on 16/9/10.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "GetStarredChannelsOfMySelfTableViewCell.h"
#import "Masonry.h"
#import "GetStarredChannelsOfMySelfContent.h"
#import "GetStarredChannelsOfMySelfJoin.h"
#import "UIImageView+WebCache.h"
@interface GetStarredChannelsOfMySelfTableViewCell ()

@property (nonatomic, strong) UIImageView *haveNewMessegeImageView;
@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UIImageView *listContentImage;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic ,strong) UILabel *contentLabel;
@property (nonatomic, strong) UIImageView *typeImageView;

@end

@implementation GetStarredChannelsOfMySelfTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
        [self getFrame];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
}

- (void)createView {
    
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.917 alpha:1.000];
    _backView = [[UIView alloc] init];
    _backView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_backView];
    
    
    _listContentImage = [[UIImageView alloc] init];
//        _listContentImage.backgroundColor = [UIColor yellowColor];
    [_backView addSubview:_listContentImage];
    _listContentImage.contentMode = UIViewContentModeScaleAspectFill;
    _listContentImage.layer.masksToBounds = YES;
    
    _titleLabel = [[UILabel alloc] init];
//        _titleLabel.backgroundColor = [UIColor grayColor];
    _titleLabel.font = [UIFont systemFontOfSize:14];
    [_backView addSubview:_titleLabel];
    
    _contentLabel = [[UILabel alloc] init];
//        _contentLabel.backgroundColor = [UIColor grayColor];
    _contentLabel.font = [UIFont systemFontOfSize:12];
    _contentLabel.text = @"adsf";
    _contentLabel.textColor = [UIColor lightGrayColor];
    [_backView addSubview:_contentLabel];
    
    _typeImageView = [[UIImageView alloc] init];
//        _typeImageView.backgroundColor = [UIColor yellowColor];
    [_backView addSubview:_typeImageView];
    
    // 创建新信息提醒标志
    _haveNewMessegeImageView = [[UIImageView alloc] init];
    _haveNewMessegeImageView.image = [UIImage imageNamed:@"hasNewPost"];
    [self.contentView addSubview:_haveNewMessegeImageView];
    
}

- (void)getFrame {
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(0);
    }];
    
    [self.listContentImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
        make.width.mas_equalTo(self.listContentImage.mas_height).multipliedBy(1.0f);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(self.listContentImage.mas_right).mas_equalTo(15);
        make.height.mas_equalTo(20);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-10);
        make.left.mas_equalTo(self.listContentImage.mas_right).mas_equalTo(15);
        make.right.mas_equalTo(-50);
        make.height.mas_equalTo(20);
    }];
    
    [self.typeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.width.mas_equalTo(17);
        make.height.mas_equalTo(15);
    }];
    
    [_haveNewMessegeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(10.0f);
        make.right.mas_equalTo(self.listContentImage.mas_right).mas_equalTo(5);
        make.top.mas_equalTo(self.listContentImage.mas_top).mas_equalTo(-5);
    }];

}

- (void)setGetStarredChannel:(GetStarredChannelsOfMySelfContent *)getStarredChannel {
    _getStarredChannel = getStarredChannel;
    [_listContentImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://qn.zheli.io/%@", _getStarredChannel.img]]];
    _titleLabel.text = _getStarredChannel.content;
    _contentLabel.text = _getStarredChannel.desc;
    if (_getStarredChannel.join.status == 3) {
        _typeImageView.image = [UIImage imageNamed:@"channelCamera"];
    } else if (_getStarredChannel.join.status == 2) {
        _typeImageView.image = [UIImage imageNamed:@"channelVoice"];
    } else {
        _typeImageView.image = [UIImage imageNamed:@"editAddress"];
    }

    if (_getStarredChannel.newCount == 0) {
        _haveNewMessegeImageView.hidden = YES;
    } else {
        _haveNewMessegeImageView.hidden = NO;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
